对称的二叉树 Posted on 2019-08-23 | | reads times 对称的二叉树题目描述 请实现一个函数,用来判断一颗二叉树是不是对称的。注意,如果一个二叉树同此二叉树的镜像是同样的,定义其为对称的。 1234567891011121314151617181920function isSymmetrical(pRoot){ // write code here if(pRoot==null){ return true; } return compare(pRoot.left,pRoot.right)}function compare(left,right){ if(left===null){ return right===null } if(right===null){ return false; } if(left.val!=right.val){ return false } return compare(left.left,right.right)&&compare(left.right,right.left)} Post author: GoldMiner Xun Post link: https://goldminerxun.github.io/2019/08/23/%E5%89%91%E6%8C%87offer%20JavaScript%E7%89%88%20(58)/ Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.